package com.hex.ds.hdrs.period.task.vo.query;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.StrUtil;
import com.hex.ds.hdrs.common.utils.HdrsDateUtil;
import lombok.Data;

import java.io.Serializable;
import java.util.Arrays;
import java.util.List;

@Data
public class PeriodTaskQueryVo implements Serializable {

    private String jobCode;

    private String jobCodeFuzzy;

    private List<String> jobCodeList;

    private String jobName;

    private List<String> jobNameList;

    private List<String> pkIds;

    private String taskCodeFuzzy;

    private String taskCode;

    private List<String> taskCodeList;

    private String taskNameFuzzy;

    private String taskName;

    private List<String> taskNameList;

    private String bizDate;

    private String shellPath;

    private String taskStatus;

    private String isEndTask;

    private String mutexJob;

    private String mutexTask;

    private String isOrder;

    private String appCode;

    private String agentCode;

    private String appointAgentCode;

    private String execStTs;

    private String execEndTs;

    private String dependJob;

    private String dependTask;

    private String extParam;

    private List<String> execStTsPicker;

    private String execStTsSt;

    private String execStTsEnd;

    private List<String> bz;

    private String startBz;

    private String endBz;

    private List<String> execEndTsPicker;

    private String execEndTsSt;

    private String execEndTsEnd;

    public List<String> getTaskCodeList() {
        if (StrUtil.isNotBlank(taskCodeFuzzy) && (taskCodeFuzzy.contains(",") || taskCodeFuzzy.contains("，"))) {
            return Arrays.asList(taskCodeFuzzy.toUpperCase().replace("，", ",").split(","));
        }
        return taskCodeList;
    }

    public String getTaskCodeFuzzy() {
        if (StrUtil.isNotBlank(taskCodeFuzzy) && (taskCodeFuzzy.contains(",") || taskCodeFuzzy.contains("，"))) {
            return null;
        }
        return (StrUtil.isNotBlank(taskCodeFuzzy)) ? taskCodeFuzzy.toUpperCase() : null;
    }

    public String getTaskNameFuzzy() {
        if (StrUtil.isNotBlank(taskNameFuzzy) && (taskNameFuzzy.contains(",") || taskNameFuzzy.contains("，"))) {
            return null;
        }
        return taskNameFuzzy;
    }

    public List<String> getTaskNameList() {
        if (StrUtil.isNotBlank(taskNameFuzzy) && (taskNameFuzzy.contains(",") || taskNameFuzzy.contains("，"))) {
            return Arrays.asList(taskNameFuzzy.replace("，", ",").split(","));
        }
        return taskNameList;
    }

    public String getJobCodeFuzzy() {
        if (StrUtil.isNotBlank(jobCodeFuzzy) && (jobCodeFuzzy.contains(",") || jobCodeFuzzy.contains("，"))) {
            return null;
        }
        return (StrUtil.isNotBlank(jobCodeFuzzy)) ? jobCodeFuzzy.toUpperCase() : null;
    }

    public List<String> getJobCodeList() {
        if (StrUtil.isNotBlank(jobCodeFuzzy) && (jobCodeFuzzy.contains(",") || jobCodeFuzzy.contains("，"))) {
            return Arrays.asList(jobCodeFuzzy.toUpperCase().replace("，", ",").split(","));
        }
        return jobCodeList;
    }

    public String getExecStTsSt() {
        if (CollectionUtil.isNotEmpty(execStTsPicker) && execStTsPicker.size() == 2) {
            return cn.hutool.core.date.DateUtil.formatDateTime(cn.hutool.core.date.DateUtil.parse(execStTsPicker.get(0), "yyyy-MM-ddHH:mm:ss"));
        }
        return execStTsSt;
    }

    public String getExecStTsEnd() {
        if (CollectionUtil.isNotEmpty(execStTsPicker) && execStTsPicker.size() == 2) {
            return cn.hutool.core.date.DateUtil.formatDateTime(cn.hutool.core.date.DateUtil.parse(execStTsPicker.get(1), "yyyy-MM-ddHH:mm:ss"));
        }
        return execStTsEnd;
    }

    public String getStartBz() {
        if (CollectionUtil.isNotEmpty(bz) && bz.size() == 2) {
            return bz.get(0);
        } else if (StrUtil.isBlank(bizDate)) {
            return HdrsDateUtil.getYesterDate();
        } else {
            return null;
        }

    }

    public String getEndBz() {
        if (CollectionUtil.isNotEmpty(bz) && bz.size() == 2) {
            return bz.get(1);
        }else if (StrUtil.isBlank(bizDate)) {
            return HdrsDateUtil.getCurrentDate();
        } else {
            return null;
        }
    }

    public String getExecEndTsSt() {
        if (CollectionUtil.isNotEmpty(execEndTsPicker) && execEndTsPicker.size() == 2) {
            return cn.hutool.core.date.DateUtil.formatDateTime(cn.hutool.core.date.DateUtil.parse(execEndTsPicker.get(0), "yyyy-MM-ddHH:mm:ss"));
        }
        return execEndTsSt;
    }

    public String getExecEndTsEnd() {
        if (CollectionUtil.isNotEmpty(execEndTsPicker) && execEndTsPicker.size() == 2) {
            return cn.hutool.core.date.DateUtil.formatDateTime(cn.hutool.core.date.DateUtil.parse(execEndTsPicker.get(1), "yyyy-MM-ddHH:mm:ss"));
        }
        return execEndTsEnd;
    }
}
